<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<#include "/common/resources.ftl"/>
<script type="text/javascript">
	$(function(){
		window.m_datagrid = $('#m_datagrid').datagrid({
			url:'${ctx}/qfbao/partnerinfo/list?op=channel',
			onLoadSuccess:yixun.closeProgress,
			onBeforeLoad:yixun.progress,
			queryParams:$('#load_list_search').serializeObject(),
			loadMsg:null,
			singleSelect:true,
			fitColumns:true,
			rownumbers:true,
			pagination:true,
			border:'false',
			toolbar:'#m_toolbar'
		});
	
		//按条件查询用户
		window.searchData = function () {
			m_datagrid.datagrid('load',$('#load_list_search').serializeObject());
		}
		
		//删除
		window.deleteDate = function(mid){
			$.messager.confirm('确认!','你确定要删除此数据吗?',function(res){
				if(res){
					$.post("${ctx}/qfbao/partnerinfo/del",{'id':mid},function(result){
						if (result.errorMsg){
							$.messager.show({
								title: '友情提示',
								msg: 'result.errorMsg'
							});
						} else {
							m_datagrid.datagrid('reload');
						}
					},'json');
				}
			});
		}
		
		//变更账户状态
		window.changeStatus = function(mid, status, optType){
            var tipMsg = "停用";
            if("1" == status && optType == '1'){
                tipMsg = "启用";
            }else if("0" == status && optType == '1'){
                tipMsg = "停用";
            }else if("0" == status && optType == '2'){
                tipMsg = "【设为管理员】";
            }else if("1" == status && optType == '2'){
                tipMsg = "【取消管理员】";
            }
			$.messager.confirm('确认!','你确定要'+tipMsg+'此数据吗?',function(res){
				if(res){
                    var params = {};
                    params["id"] = mid;
                    if(optType == '1'){
                        params["status"] = status;
                    }else if(optType == '2'){
                        params["accountType"] = status;
                    }
                    console.log();
					$.post("${ctx}/qfbao/partnerinfo/changeStatus",params,function(result){
						if (result.errorMsg){
							$.messager.show({
								title: '友情提示',
								msg: 'result.errorMsg'
							});
						} else {
							m_datagrid.datagrid('reload');
						}
					},'json');
				}
			});
		}
	});
	mShowButton = function (value,row,index){
		var btns = [];
		//btns.push('<button class="green_btn" onclick="javascript:deleteDate('+value+');void(0);">删除</button>');
		if("1" == row.status){
			//启用中账户,停用
			btns.push('<button class="green_btn" onclick="javascript: changeStatus('+value+',0,1);void(0);">停用</button>');
		}else if("0" == row.status){
			//停用中账户,启用
			btns.push('<button class="green_btn" onclick="javascript: changeStatus('+value+',1,1);void(0);">启用</button>');
		}

        if("0" == row.accountType){
            //启用中账户,停用
            btns.push('<button class="green_btn" onclick="javascript: changeStatus('+value+',1,2);void(0);">取消管理</button>');
        }else if("1" == row.accountType){
            //停用中账户,启用
            btns.push('<button class="green_btn" onclick="javascript: changeStatus('+value+',0,2);void(0);">设为管理</button>');
        }
		
		return btns.join('');
	}
	
	jumpDetail = function (value,row,index){
		var btns = [];
		btns.push('<a style="color:red" href="javascript:window.location.href=\'view?isView=0&id='+row.id+'\'">'+value+'</a>');
		return btns.join('');
	}
</script>
</head>
<body style="background-color:white;">

<div id="m_toolbar" class="datagrid-toolbar" style="overflow: hidden;height: auto;margin: 15px 0px;background-color: white;border-bottom: none;" border="false">
  <form id="load_list_search" onsubmit="return false;">
  <div class="fm_sty" style="margin: 20px 0px 0px;">

   	<div class="ipt_line">
	<span class="ipt_title">姓名</span>
		<input type="text" name="accountName" class="ipt_226" />
	</div>
   	<div class="ipt_line">
	<span class="ipt_title">所属渠道商</span>
		<input type="text" name="companyName" class="ipt_226" />
	</div>
   	<div class="ipt_line">
	<span class="ipt_title">手机</span>
		<input type="text" name="phone" class="ipt_226" />
	</div>
	
	<div class="ipt_line_long">
        <button class="red_100" onclick="searchData()">查询</button>
	</div>    
  </div>
  </form>
</div>

<!-- 查找结果 -->
<table style="margin:0px 20px;" id="m_datagrid">
	<thead>
		<tr>
			<th width="60" height="40" data-options="field:'accountName',formatter:jumpDetail">姓名</th>
			<th field="phone" width="60" height="40" >手机</th>
			<th data-options="field:'status',formatter:function(value,row,index){var key = 'mechanism_status';return yixun.combobox_formatter(value,row,index,key);}" width="60" height="40" >状态</th>
			<th data-options="field:'accountType',formatter:function(value,row,index){var key = 'mechanism_account_type';return yixun.combobox_formatter(value,row,index,key);}" width="60" height="40" >账户类型</th>
			<th field="companyName" width="60" height="40" >所属渠道商</th>
			<th field="createTime" width="90" height="40" >创建时间</th>
            <th data-options="field:'id',formatter:mShowButton,align:'center'" width="150">操作</th>
		</tr>
	</thead>
</table>

</body>
</html>
